package com.zzxy.po;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

import javax.security.auth.Destroyable;

public class User implements BeanNameAware , InitializingBean , DisposableBean {
    private String username;

    private String password;

    private String sex;

    public User() {
        System.out.println("1. init bean ...");
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        System.out.println("2. set properties ...");
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("3. set bean name "  + s);
    }

//    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4. set bean factory ...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6. after properties set ... ");
    }

    public void myInit() {
        System.out.println("7. my init method ... ");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9. destroy ...");
    }

    public void myDestroy() {
        System.out.println("10. my destroy method ...");

    }


    /*
    * 1.instantiate bean对象实例化
2.populate properties 封装属性
3.如果Bean实现BeanNameAware 执行 setBeanName
4.如果Bean实现BeanFactoryAware 执行setBeanFactory ，获取Spring容器
5.如果存在类实现 BeanPostProcessor（后处理Bean） ，执行postProcessBeforeInitialization
6.如果Bean实现InitializingBean 执行 afterPropertiesSet
7.调用<bean init-method="init"> 指定初始化方法 init
8.如果存在类实现 BeanPostProcessor（处理Bean） ，执行postProcessAfterInitialization
执行业务处理
9.如果Bean实现 DisposableBean 执行 destroy
10.调用<bean destroy-method="customerDestroy"> 指定销毁方法 customerDestroy
5.3 演示
* */
}